package com.njwb.day18.thd03;

public class PriorityDemo {
    public static void main(String[] args) {
        PriorityThread  priorityThread= new PriorityThread() ;

        Thread st1 = new Thread(priorityThread,"线程1");
        Thread st2 = new Thread(priorityThread,"线程2");
        Thread st3 = new Thread(priorityThread,"线程3");

        //设置线程优先级
        st1.setPriority(5);
        st2.setPriority(10);
        st3.setPriority(1);

        st1.start();
        st2.start();
        st3.start();

    }
}



class PriorityThread implements Runnable {

    @Override
    public void run() {
        if(Thread.currentThread().getName().equals("线程1")) {
            for(int i =1 ; i<10 ; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        } else if(Thread.currentThread().getName().equals("线程2")) {
            for(int i =11 ; i<20 ; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        } else if(Thread.currentThread().getName().equals("线程3")) {
            for(int i =21 ; i<30 ; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}
